package com.le.tester.book.effectivejava3rdchinese.secondReading.l48;

import java.math.BigInteger;
import java.util.stream.Stream;

/**
 * createTime：2024-10-08 9:44
 * description：谨慎使用流并行
 */
public class Demo {

    public boolean f(int i) {
        switch (i) {
            case 0:
                return false;
            case 1:
                return true;
        }

        return false;
    }

    public static final BigInteger TWO = BigInteger.valueOf(2L);
    public static final BigInteger ONE = BigInteger.valueOf(1L);

    public static void main(String[] args) {

        //isProbablePrime()是不是素数
        primes().map(item -> TWO.pow(item.intValueExact()).subtract(ONE))
                .filter(mersenne -> mersenne.isProbablePrime(50))
                .limit(20)
                .forEach(System.out::println);

    }

    static Stream<BigInteger> primes() {
        return Stream.iterate(TWO, BigInteger::nextProbablePrime);
    }
}
